/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package titanisu.basicMathModule1.quardraticEquation;

import java.util.ArrayList;
import java.util.Random;

/**
 *
 * @author Balaji
 */
public class QuestionGenerator {
    ArrayList quest = new ArrayList();

    private void setQ(ArrayList arlst) {
        this.quest = arlst;
    }
    
    
public ArrayList getQuest()
{
    return quest;
}

public void setQuest(ArrayList quest)
{
    this.quest = quest;
}
    
    
    
    public String getQuestions() {
        titanisu.templates.helperClasses.MainHelper mh = new titanisu.templates.helperClasses.MainHelper();
        ArrayList template = mh.getMMLTemplateFor("qe", 1);
        ArrayList quest = mh.resolveTemplateWithConstratints(template);
        
        setQ(quest);
        
        System.out.println("(String) quest.get(0) = " + (String) quest.get(0));
        return (String) quest.get(0);

    }

 
    public void getOptions() {
        String[] options = new String[4];
        Random r = new Random();

        if (quest.size() > 2) {
            options[0] = " <math>  <mfrac>       <mi>" + quest.get(1) + "</mi>  <mi>" + quest.get(2) + "</mi>    </mfrac> </math>  ";
            options[1] = "  <math>  <mfrac>       <mi>" + r.nextInt(30) + "</mi>  <mi>" + r.nextInt(30) + "</mi>    </mfrac> </math>";
            options[2] = " <math>   <mfrac>       <mi>" + r.nextInt(30) + "</mi>  <mi>" + r.nextInt(30) + "</mi>    </mfrac></math> ";
            options[3] = "  <math>  <mfrac>       <mi>" + r.nextInt(30) + "</mi>  <mi>" + r.nextInt(30) + "</mi>    </mfrac></math> ";

        } else {
            r.nextInt(30);
            options[0] = (String) quest.get(1);
            options[1] = r.nextInt(30) + "";
            options[2] = r.nextInt(30) + "";
            options[3] = r.nextInt(30) + "";
        }

}
    
        /**
         *
         * @return
         */
    

    public String getAnswer() 
    {
        String answer = "<math>  ";
        if(quest.get(3)!=null)
        {
            answer = "<math>";
            ArrayList solutions =  (ArrayList) quest.get(3);
            for (int i = 0; i < solutions.size(); i++) {
                if(i%2==0)
                {
                    answer +="<mrow> <mfrac>";
                
                    answer += ( "<mi>" + solutions.get(i) + "</mi> <mi> " + solutions.get(i) + "</mi>" );
                answer +=" </mfrac> </mrow> ";
                }
                
                
                
            }
            answer+="</math>";
            
            System.out.println("answer = " + answer);
        }
        else
        
        if (quest.size() > 2) {
            answer = " <math>  <mfrac>       <mi>" + quest.get(1) + "</mi>  <mi>" + quest.get(2) + "</mi>    </mfrac> </math>";
        } else {
            answer = " <math>  <mn> "+(String) quest.get(1) +"</mn> </math>";
        }
        return answer;

    }
       
}
